<template>
    <h1>投资项目修改页面</h1>

    <table>
        <tr>
            <td>投资名称</td>
            <td>
                <input type="text" v-model="Info.I_Name">
            </td>
        </tr>

        <tr>
            <td>投资总额度</td>
            <td>
                <input type="text" v-model="Info.I_SumMoney">
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="修改" @click="Update" >
            </td>
        </tr>

    </table>

</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';

const router = useRouter();

const Info = ref({
    I_Name:'',
    I_SumMoney:'',
})

const route = useRoute();

console.log(route.params.Id);

onMounted (()=>{
    axios({
        method:'get',
        url:'http://localhost:51401/api/Invest/SeraInvest',
        params:{
            Id:route.params.Id
        }
    })
    .then(res=>{
        console.log(res.data);
        Info.value = res.data;
    })
    .catch(err=>{
        console.log(err);
    })
})

const Update =()=>{
    axios({
        method:'post',
        url:'http://localhost:51401/api/Invest/Update',
        data:{
            I_Id:route.params.Id,
            I_Name:Info.value.I_Name,
            I_SumMoney:Info.value.I_SumMoney
        }
    })
    .then(res=>{
        if(res.data>0){
            alert('修改成功');
            router.push('/');

        }else{
            alert('修改失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })

}


</script>